import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { StatusMonitorModule } from 'nest-status-monitor';
import StatusConfig from './common/define';
import { WxhttpModule } from './module/wxhttp/wxhttp.module';
import { WxsocketsModule } from './module/wxsockets/wxsockets.module';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ClientsModuleOptions } from '@nestjs/microservices/module/interfaces/clients-module.interface';
import { LoggerMiddleware } from './middleware/logger.middleware';
import { MongooseModule } from '@nestjs/mongoose';
import { StatusModule } from './controller/status/status.module';
import { ChatController } from './controller/chat/chat.controller';
import { UserController } from './controller/user/user.controller';
import { UserModule } from '@app/user';

// import { UserModule } from './controller/user/user.module';

const config: ClientsModuleOptions = [
  {
    name: 'WX_SERVICE',
    transport: Transport.REDIS,
    options: {
      url: 'redis://localhost:6379',
    },
  },
];
@Module({
  imports: [
    StatusModule,
    ClientsModule.register(config),
    StatusMonitorModule.setUp(StatusConfig),
    WxsocketsModule,
    WxhttpModule,
    MongooseModule.forRoot('mongodb://localhost/wxlog'),
    UserModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes('home');
  }
}
